package com.example.academicsystem.server.controller.student;

import com.example.academicsystem.pojo.dto.CourseDto;
import com.example.academicsystem.pojo.dto.CourseTableDto;
import com.example.academicsystem.pojo.dto.StudentCourseDeleteDto;
import com.example.academicsystem.pojo.dto.StudentCourseInsertDto;
import com.example.academicsystem.pojo.vo.CourseTableVo;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.result.Result;
import com.example.academicsystem.server.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student/course")
@Slf4j
public class StudentCourseController {
    @Autowired
    private StudentService studentService;

    /**
     * 分页查询课程(所有或者根据课程名称模糊查询)
    * */
    @PostMapping("/page")
    public Result<PageResult> studentCoursePageQuery(@RequestBody CourseDto courseDto){
        log.info("studentCoursePageQuery");
        PageResult pageResult = studentService.studentCoursePageQuery(courseDto);
        return Result.success(pageResult);
    }

    /**
     * 根据学期（term：1，2，3。。。）查询课程表
    **/
    @PostMapping("/table")
    public Result<List<CourseTableVo>> studentCourseTableQuery(@RequestBody CourseTableDto courseTableDto){
        log.info("studentCourseTableQuery");
        List<CourseTableVo> courseTableVoList = studentService.CourseTableQuery(courseTableDto);
        return Result.success(courseTableVoList);
    }

    @PostMapping("/insert")
    public Result studentCourseInsert(@RequestBody StudentCourseInsertDto studentCourseInsertDto){
        log.info("studentCourseInsert");
        studentService.studentCourseInsert(studentCourseInsertDto);
        return Result.success();
    }

    @DeleteMapping("/delete")
    public Result studentCourseDelete(@RequestBody StudentCourseDeleteDto studentCourseDeleteDto){
        log.info("student course delete");
        studentService.courseDelete(studentCourseDeleteDto);
        return Result.success();
    }

}
